package main

import (
    "github.com/go-martini/martini"
    "github.com/jinzhu/gorm"
    _ "github.com/go-sql-driver/mysql"
    "encoding/json"
)


type User struct {
    Id           int64
    UserName         string  `sql:"size:40"`
    Password         string  `sql:"size:40"`
}

func main() {
	m := martini.Classic()
	db, _ := gorm.Open("mysql", "root:th@/test?charset=utf8&parseTime=True")
	db.DB()

	db.DB().Ping()
	db.DB().SetMaxIdleConns(10)
	db.DB().SetMaxOpenConns(100)

	db.SingularTable(true)
	users := []User{};
	db.Find(&users)

	m.Get("/", func() string {
		b, _ := json.Marshal(users)
		return string(b)
	})
	m.Run()
}
